package com.example.myapplication.hospital;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.InquirycaseBean;
import com.google.gson.Gson;

public class DoctordetailsActivity extends AppCompatActivity {

    private String doctordetailsbane;
    private InquirycaseBean.RowsBean rowsBean;
    private ImageView bloak;
    private ImageView img;
    private TextView name;
    private TextView jobName;
    private TextView practiceNo;
    private TextView question;
    private TextView doctorreply;
    private LinearLayout li_submit;
    private Gson gson;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_doctordetails);
        initviewe();
        //返回
        but_bloak();
        //填充信息
        doctorfillinformation();
        //点击提问
        askaquestion();

    }

    private void askaquestion() {
        li_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(DoctordetailsActivity.this,ConsultationpageActivity.class);
                String Bean = gson.toJson(rowsBean.getDoctor());
                intent.putExtra(Commom.CONSULTATIONPAGE_ID,Bean);
                DoctordetailsActivity.this.startActivity(intent);
            }
        });
    }

    private void doctorfillinformation() {
        InquirycaseBean.RowsBean.DoctorBean doctor = rowsBean.getDoctor();
        if(doctor!=null){
            if(!TextUtils.isEmpty(doctor.getAvatar())){
                Glide.with(DoctordetailsActivity.this).load(TokenBean.IP+doctor.getAvatar()).into(img);
            }
            if (!TextUtils.isEmpty(doctor.getName())) {
                name.setText(doctor.getName());
            }else {
                name.setText("暂无信息");
            }
            if (!TextUtils.isEmpty(doctor.getJobName())){
                jobName.setText(doctor.getJobName());
            }else {
                jobName.setText("暂无信息");
            }

            if (!TextUtils.isEmpty(doctor.getPracticeNo())){
                practiceNo.setText(doctor.getJobName());
            }else {
                practiceNo.setText("暂无信息");
            }

            if (!TextUtils.isEmpty(rowsBean.getQuestion())){
                question.setText(rowsBean.getQuestion());
            }else {
                question.setText("暂无信息");
            }
        }

    }


    private void but_bloak() {
        bloak.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DoctordetailsActivity.this.finish();
            }
        });
    }
    private void initviewe() {
        Intent intent = getIntent();
        doctordetailsbane = intent.getStringExtra(Commom.DOCTORDETAILSBANE);
        gson = new Gson();
        rowsBean = gson.fromJson(doctordetailsbane, InquirycaseBean.RowsBean.class);
        bloak = findViewById(R.id.bloak);


        img = findViewById(R.id.img);
        name = findViewById(R.id.name);
        jobName = findViewById(R.id.jobName);
        practiceNo = findViewById(R.id.practiceNo);
        question = findViewById(R.id.question);
        doctorreply = findViewById(R.id.doctorreply);
        li_submit = findViewById(R.id.li_submit);


    }
}